﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Common;
using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Chi.Lib.DBHelper;

public partial class testaspx : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ServerConnection conn = new ServerConnection();
        conn.ConnectionString = DBHelperConnection._ConnStr;
        Server server = new Server(conn);

        Database db = server.Databases["Northwind"];

        //StoredProcedureCollection spc = db.StoredProcedures;

        this.DropDownList1.DataSource = db.Tables;
        this.DropDownList2.DataSource = db.Views;
        this.DropDownList3.DataSource = db.StoredProcedures;
        this.DropDownList4.DataSource = db.UserDefinedFunctions;
        this.DropDownList5.DataSource = db.Triggers;




        this.DropDownList1.DataBind();
        this.DropDownList2.DataBind();
        this.DropDownList3.DataBind();
        this.DropDownList4.DataBind();
        this.DropDownList5.DataBind();

        

        Microsoft.Web.UI.WebControls.TreeNode tbNode =
            new Microsoft.Web.UI.WebControls.TreeNode();
        tbNode.ID = "0";
        tbNode.Text = "Table";
        tbNode.Type = "FOLDER";
        tbNode.ImageUrl = "/images/root.gif";
        foreach (Microsoft.SqlServer.Management.Smo.Table tb in db.Tables)
        {
            Microsoft.Web.UI.WebControls.TreeNode tbCNode =
            new Microsoft.Web.UI.WebControls.TreeNode();
            tbCNode.Text = tb.Name;
            tbCNode.ID = tb.ID.ToString();
            tbCNode.ImageUrl = "/images/folder.gif";
            tbNode.Nodes.Add(tbCNode);
        }
        this.TreeView1.Nodes.Add(tbNode);
    }
}
